package org.xiaohanghu.starter.net;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

/**
 * @author xiaohanghu
 */
public class ClassPathUrlConvertor implements UrlConvertor {

	public static final String URI_SCHEME = "classpath";

	@Override
	public URL convert(URI uri) throws MalformedURLException,
			URISyntaxException {
		String path = uri.getSchemeSpecificPart();
		if (path.startsWith("/")) {
			path = path.substring(1);
		}
		return Thread.currentThread().getContextClassLoader().getResource(path);
	}

}
